package com.ruoyi.extend.service.impl;

import java.util.List;
import java.util.Map;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.db.domain.CountInfo;
import com.ruoyi.db.mapper.CountInfoMapper;
import com.ruoyi.db.model.excle.CountUvInfoExcel;
import com.ruoyi.db.model.param.CountUvInfoParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.db.mapper.CountUvInfoMapper;
import com.ruoyi.db.domain.CountUvInfo;
import com.ruoyi.extend.service.ICountUvInfoService;
import com.ruoyi.common.core.text.Convert;

import javax.annotation.Resource;

/**
 * uvCountInfoService业务层处理
 * 
 * @author ruoyi
 * @date 2022-10-27
 */
@Service
@DataSource(DataSourceType.SLAVE)
public class CountUvInfoServiceImpl implements ICountUvInfoService 
{
    @Autowired
    private CountUvInfoMapper countUvInfoMapper;
    @Resource
    private CountInfoMapper countInfoMapper;

    /**
     * 查询uvCountInfo
     * 
     * @param id uvCountInfo主键
     * @return uvCountInfo
     */
    @Override
    public CountUvInfo selectCountUvInfoById(Long id)
    {
        return countUvInfoMapper.selectCountUvInfoById(id);
    }

    /**
     * 查询uvCountInfo列表
     * 
     * @param countUvInfo uvCountInfo
     * @return uvCountInfo
     */
    @Override
    public List<CountUvInfoExcel> selectCountUvInfoList(CountUvInfo countUvInfo)
    {
        return countUvInfoMapper.selectCountUvInfoList(countUvInfo);
    }

    /**
     * 查询uvCountInfo列表
     *
     * @return uvCountInfo
     */
    @Override
    public List<Map<String, Object>> selectCountUvInfoListMap(CountUvInfo countUvInfo)
    {

        if (ObjectUtil.isNotEmpty(countUvInfo.getCreateTime())){
            CountInfo countInfo = countInfoMapper.selectCountInfoById(String.valueOf(countUvInfo.getCountId()));
            if (StrUtil.isNotEmpty(countUvInfo.getStartCreateTime())){
                countUvInfo.setStartCreateTime(countInfo.getDateInfo() + " " + countUvInfo.getStartCreateTime());
            }

            if (StrUtil.isNotEmpty(countUvInfo.getEndCreateTime())){
                countUvInfo.setEndCreateTime(countInfo.getDateInfo() + " " + countUvInfo.getEndCreateTime());
            }
        }

        return countUvInfoMapper.selectCountUvInfoListMap(countUvInfo);
    }

    /**
     * 新增uvCountInfo
     * 
     * @param countUvInfo uvCountInfo
     * @return 结果
     */
    @Override
    public int insertCountUvInfo(CountUvInfo countUvInfo)
    {
        return countUvInfoMapper.insertCountUvInfo(countUvInfo);
    }

    /**
     * 修改uvCountInfo
     * 
     * @param countUvInfo uvCountInfo
     * @return 结果
     */
    @Override
    public int updateCountUvInfo(CountUvInfo countUvInfo)
    {
        return countUvInfoMapper.updateCountUvInfo(countUvInfo);
    }

    /**
     * 批量删除uvCountInfo
     * 
     * @param ids 需要删除的uvCountInfo主键
     * @return 结果
     */
    @Override
    public int deleteCountUvInfoByIds(String ids)
    {
        return countUvInfoMapper.deleteCountUvInfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除uvCountInfo信息
     * 
     * @param id uvCountInfo主键
     * @return 结果
     */
    @Override
    public int deleteCountUvInfoById(Long id)
    {
        return countUvInfoMapper.deleteCountUvInfoById(id);
    }
}
